package com.xiaohao.communication.controller;


import com.xiaohao.communication.bean.Collection;
import com.xiaohao.communication.service.UserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserCollectionController {

    @Autowired
    UserCollectionService userCollectionService;



    //获取收藏                  success
    @GetMapping("/query-collection")
    @ResponseBody
    public List<Collection> getCollection(String username ) {
        List<Collection> collection = userCollectionService.getCollection(username);
        return collection;
    }

    //增加收藏                  success
    /*
    * 只传送本人用户名和话题id
    * */
    @GetMapping("/add-collection")
    @ResponseBody
    public void addCollection(Collection collection) {
        collection.setCollectionState(1);
        userCollectionService.addCollection(collection);

    }


    /*
     *  删除收藏的话题         success
     *
     *  对于删除，前端只传送话题id，改变状态码为0；  1为存在，0为删除
     * */
    @GetMapping("/delete-collection")
    @ResponseBody
    public void deleteCollection(int topic_id) {
        userCollectionService.deleteCollection(topic_id);
    }




}
